package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TDisease;
import com.myProject.dao.DiseaseDao;
import com.myProject.serves.DiseaseSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class DiseaseSevImpl implements DiseaseSev {
    @Override
    public List<TDisease> getDiseaseList(TDisease tDisease) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        DiseaseDao diseaseDao= sqlSession.getMapper(DiseaseDao.class);
        List<TDisease>list  = diseaseDao.getDiseaseList(tDisease);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public PageInfo<TDisease> showDiseaseByPage(int pageNo, int pageSize, TDisease tDisease) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        DiseaseDao dd = sqlSession.getMapper(DiseaseDao.class);
        PageHelper.startPage(pageNo,pageSize);
        List<TDisease>list = dd.getDiseaseList(tDisease);
        PageInfo<TDisease>page = new PageInfo<TDisease>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }

    @Override
    public int addDisease(TDisease tDisease) {
        SqlSession sqlSession=SqlSessionUtil.getSqlSession();
        DiseaseDao dd = sqlSession.getMapper(DiseaseDao.class);
        int x = dd.addDisease(tDisease);
        SqlSessionUtil.commit();
        sqlSession.close();
        return x;
    }
}
